package sandbox.psyomn;

import java.util.ArrayList;
import java.util.Date; 

import Model.SingleTask;


/**
 * Demonstration on how to use the stargates : ) 
 * 
 * @author psyomn
 */

public class SingleGateway
{
	public static void main(String[] args)
	{
		// run these one at the time, top to bottom
		// createDatabase();
		// readDatabase();
		// deleteTask();
		// update();
	}
	
	public static void createDatabase()
	{
		SingleTaskGateway stg = new SingleTaskGateway(); 
		
		SingleTask st1 = new SingleTask("task1", new Date(), "desc1");
		SingleTask st2 = new SingleTask("task2", new Date(), "desc2");
		SingleTask st3 = new SingleTask("task3", new Date(), "desc3");
		SingleTask st4 = new SingleTask("task4", new Date(), "desc4");
		
		/* First time when runned, should work, 
		 * expect an exception on second run */
		stg.create(st1);
		stg.create(st2);
		stg.create(st3);
		stg.create(st4);
	}
	
	public static void readDatabase()
	{
		SingleTaskGateway stg = new SingleTaskGateway(); 

		ArrayList<SingleTask> starr; 
		
		starr = stg.read();
		System.out.println(starr);
	}
	
	public static void deleteTask()
	{
		SingleTaskGateway stg = new SingleTaskGateway();
		SingleTask st1 = new SingleTask("task1", new Date(), "desc1");
		ArrayList<SingleTask> starr;
		
		stg.delete(st1);
		
		starr = stg.read();
		System.out.println(starr);
	}
	
	public static void update()
	{
		SingleTaskGateway stg = new SingleTaskGateway();
		SingleTask st1 = new SingleTask("task2", new Date(), "Single");
		ArrayList<SingleTask> starr;
		
		starr = stg.read();
		System.out.println(starr);
		
		st1.setDone(true);
		
		/* You should observe a new timestamp for t2, and that it's done */
		stg.update(st1);
		
		starr = stg.read();
		System.out.println(starr);
	}
}
